import React, { Component, Fragment } from 'react';
import { WeaDialog,WeaTools } from 'ecCom';
import { WeaTableNew} from 'comsMobx';
import { Button, Progress, message } from 'antd';
const WeaTable = WeaTableNew.WeaTable;
const {TableStore} = WeaTableNew;
export default class OfdNumberListCom extends Component {
    constructor(props) {
        super(props);
        this.requestid = -1;
        this.docid = -1;
        this.param = '';
        this.otherparam = '';

        this.tableStore=new TableStore();
        this.state = {
            visible:true,
            buttonstatus : false

        }
    }

    componentDidMount() {
        this.getNmberList();
    }


    getNmberList =()=> {
        const ofdNumberListCom = document.getElementById('ofdNumberListCom');

        if (ofdNumberListCom.getAttribute('requestid')) {
            this.requestid = ofdNumberListCom.getAttribute('requestid');
        }
        if (ofdNumberListCom.getAttribute('docid')) {
            this.docid = ofdNumberListCom.getAttribute('docid');
        }
        if (ofdNumberListCom.getAttribute('param')) {
            this.param = ofdNumberListCom.getAttribute('param');
        }
        if (ofdNumberListCom.getAttribute('otherparam')) {
            this.otherparam = ofdNumberListCom.getAttribute('otherparam');
        }
        const arrparam=JSON.parse(this.otherparam)
        window.console.log(arrparam);
        arrparam.map(item =>{
            if(item.zt!="1"){
                this.setState({
                    buttonstatus:true
                });

            }
        })
        const data = {
            requestid: this.requestid,
            docid: this.docid,
            otherParam: this.param
        };

        WeaTools.callApi("/api/odoc/odocWorkflow/getNumberList", 'POST', data).then(data => {
            if (data.api_status) {
                this.tableStore=this.tableStore.getDatas(data.datas)

            } else {
                message.error(data.api_errormsg);
            }
        })
    }

    createNumber=()=>{
        const data = {
            requestid: this.requestid,
            docid: this.docid,
            otherParam: this.otherparam
        };
        message.loading("重新生成份号中,请稍等...")
        WeaTools.callApi('/api/odoc/odocWorkflow/writeNumberToFile', 'POST', data).then((data) => {

            if(data.api_status){
                let i=0;
                data.data.map(item =>{
                    window.setDetailCl(i,item.status,item.Number);
                    i++;
                })
            }
            WfForm.doSave();
        });
    }
    getButtons = () => {
        let buttons = []


            buttons = [
                this.state.buttonstatus&&<Button type="primary" onClick={() => {
                    this.createNumber()
                }}>重新生成</Button>,
                <Button type="primary" onClick={() => { this.removeDialog() }}>关闭</Button>
            ]

        return buttons

    }



removeDialog = () => {

    this.setState({
        visible: false
    })
    const ofdNumberListCom = document.getElementById('ofdNumberListCom');
    ofdNumberListCom.parentNode.removeChild(ofdNumberListCom);
}

render() {

    return (
        <div id="ofdNumberListCom">
            <WeaDialog
                title={'份号列表'}
                visible={this.state.visible}
                buttons={this.getButtons()}
                style={{ height: 800,width:1200}}
                onCancel={this.removeDialog}
                destroyBodyOnClose={true}
            >
                <div class="OfdNumberListTable">
                    <WeaTable
                        comsWeaTableStore={this.tableStore}
                    />
                </div>
            </WeaDialog>
        </div>

    );

}
    }